//终端日常维护日志列表 0

//(function(){
define(function(require, exports, module){	
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
	var wind_async=require('ddf_wind_async');
		
	var base=require('component-base');
	var history=require('component-history');
	require('component-page');
var beginDate,endDate,terminalId,typesId,userName,realName;

var tips_index=0;
var pageSize=0;
/**
 * 查询终端日常维护日志列表
 */
//function loadqueryTerminalLogsList(){
exports.init = function(m){
	history.addHis(this,arguments);//增加历史
	 window.$ddf_terminalLogs = m;
	
	var htmlStr="";
	
    	htmlStr += '<div id="content-header">';
    	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="#" class="current">日志管理</a></div>';
    	htmlStr += '</div>    ';
    	htmlStr += '<div class="container-fluid">';
    	htmlStr += '<div class="row-fluid">';
    	htmlStr += '<div class="span12">';
    	
    	htmlStr += '<div id="alert-tips0" ></div>';
    	
    	htmlStr += '<div class="widget-box">';
    	htmlStr += '<div class="widget-title">';
    	htmlStr += '<span class="icon">';
    	htmlStr += '<i class="icon-search"></i>';
    	htmlStr += '</span>';
    	htmlStr += '<h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button>';
    	htmlStr += '</div> ';    	    	
    	htmlStr += '<div class="widget-content nopadding">';
    	htmlStr += '<form class="form-horizontal">'; 
    	
    	htmlStr += '<div class="row-fluid">';   	
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">创建时间：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span4 m-wrap" type="text" id="beginDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false})  />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap" type="text" id="endDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) />';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">操作类型：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<select id="select-types"></select>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';   	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="row-fluid">';   	
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">操作帐号：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span8 m-wrap" type="text" id="userName"/> ';   	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span8 m-wrap" type="text" id="realName"/> ';   	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
  /*  	htmlStr += '<div class="row-fluid">';   	
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">终端编码：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span8 m-wrap" type="text" id="terminalId"/> ';   	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="span6">';
    	htmlStr += '</div>';
    	htmlStr += '</div>';*/
    	
    	  	
    	htmlStr += '<div class="form-actions">';
    	htmlStr += '<button class="btn btn-primary" type="button" onclick="$ddf_terminalLogs.searchTerminalLogs()">搜索</button>';
    	htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_terminalLogs.resetSearchParams()">重置</button>';
    	htmlStr += '</div>';
    	htmlStr += '</form>';
    	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="widget-box">';
    	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
    	htmlStr += '<h5>日志列表</h5>';
    	htmlStr += '</div>';
    	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
    	htmlStr += '<table class="table table-bordered data-table record">';
    	htmlStr += '<thead>';
    	htmlStr += '<tr>';
    	htmlStr += '<th>序号</th>';
    	htmlStr += '<th>操作帐号</th>';
    	htmlStr += '<th>姓名</th>';
    	//htmlStr += '<th>终端代码</th>';
    	htmlStr += '<th>操作类型</th>';
    	htmlStr += '<th>记录时间</th>';
    	htmlStr += '<th>操作详细内容</th>';
    	htmlStr += '</tr>'; 
    	htmlStr += '</thead>';
    	htmlStr += '<tbody id="terminalLogsList">';
    	
    	htmlStr += '</tbody>';
    	htmlStr += '</table>';
    	
    	htmlStr += '<div  id="footPageDiv0">';
   
    	htmlStr += '</div>';
    	htmlStr += '</div>';    	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
//    	$("#content0").css("display","block");
    	showDiv("content0");
    	$("#content0").html(htmlStr);
    	getTypeList("select-types","");
    	getQueryTerminalLogs(1,pageSize,beginDate,endDate,terminalId,typesId,userName,realName);	
    	
    	
	
}


/**
 * 查询终端日常维护日志列表
 * @param beginDate
 * @param endDate
 * @param terminal
 * @param terminal
 * @param terminal
 */
function getQueryTerminalLogs(pageNumber,pageSize,beginDate,endDate,terminalId,typesId,userName,realName){
	
	var params={
			"page.pageNumber":pageNumber,
			"page.pageSize" : pageSize,
			"beginDate":beginDate,
			"endDate":endDate,
			"terminalId":terminalId,
			"userName":userName,
			"realName":realName,
			"type":typesId
	        };
	
	tips_index=0;

	base.showLoading();
	
//	DDF_AsyncRequest("POST",ddf.log.queryTerminalLogs,params,'$ddf_terminalLogs.loadqueryTerminalLogsListCallBack(data)');
	 eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.log.queryTerminalLogs,params));
			
			loadqueryTerminalLogsListCallBack(data);
			
		}))().start();

	
}

function loadqueryTerminalLogsListCallBack(data){
	if(data["code"]==1){
    	var htmlStr="";
    	for(var i=0;i<data["terminalLogsListData"].length;i++){
    		
    		htmlStr += ' <tr>';
    		htmlStr += '<td>'+getSequence(data["pageNumber"],i+1)+'</td>';
    		htmlStr += '<td>'+data["terminalLogsListData"][i]["USER_NAME"]+' </td>';
    		htmlStr += '<td>'+data["terminalLogsListData"][i]["REAL_NAME"]+' </td>';
    		//htmlStr += '<td>'+data["terminalLogsListData"][i]["TERMINAL_ID"]+' </td>';
    		htmlStr += '<td>'+data["terminalLogsListData"][i]["LOG_TYPE_NAME"]+' </td>';
    		htmlStr += '<td>'+data["terminalLogsListData"][i]["CREATE_TIME"]+' </td>';
    		htmlStr += '<td>'+data["terminalLogsListData"][i]["MEMO"]+' </td>';
    		
    		 
    		htmlStr += '</tr> ';
    		
    	}
    	$("#terminalLogsList").html(htmlStr);
    
//		setPage(0,data["pageNumber"],data["totalCount"],data["totalPage"],"$ddf_terminalLogs");
    	$('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
			 
			 changePageCallback:function(pageSize,page){  
//				 getQueryBankList(page,pageSize);
				 getQueryTerminalLogs(page,pageSize,beginDate,endDate,terminalId,typesId,userName,realName)

			 },
			 changePageSizeCallBack:function(pageSize){
//				 getQueryBankList(1,pageSize);
				 getQueryTerminalLogs(1,pageSize,beginDate,endDate,terminalId,typesId,userName,realName)
	     	 
			 } 
	     }); 

	}else{
		
		 
		 base.tips_error(data["message"]);

		
	}

	base.cancelLoading();
}

/**
 * 重置参数
 */
function resetSearchParams(){
	
	
	beginDate="";
	
	endDate="";
	
	terminalId="";
	
	typesId="";
	
	userName="";
	
	realName="";
	
	getTypeList("select-types","");
	
	$("#beginDate").val("");
	
	$("#endDate").val("");
	
	$("#terminalId").val("");
	
	$("#userName").val("");
	
	$("#realName").val("");
	
	
}

/**
 * 搜索终端日常维护日志
 */
function searchTerminalLogs(){
	

	beginDate=$("#beginDate").val();
	
	endDate=$("#endDate").val();
	
	terminalId=$("#terminalId").val();
	
	userName=$("#userName").val();
	
	realName=$("#realName").val();
	
	
	if(typesId=="0"||typesId=="-1"){
		typesId="";
	}
	
	
	if(!base.checkDate(beginDate,endDate))
		return;
	
	getQueryTerminalLogs(1,pageSize,beginDate,endDate,terminalId,typesId,userName,realName);	
	
}



/**
 * 选择操作类型
 */
function setType(_typeId){
	
	typesId=_typeId;
		
	
}
/**
 * 查询操作类型
 */
var out_put_id,setTypeIdFlag=false;

function getTypeList(id,_typeId){
	
	out_put_id=id;
	
	if(_typeId!="")
		setType(_typeId);
	
	
	 eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.log.getQueryType,""));
			
			getTypeListCallBack(data);
			
		}))().start();
	
}

/**
 * 操作类型回调函数
 */
var typeListHtmlStr="";

function getTypeListCallBack(data){
	
	
	typeListHtmlStr="";
	
	var beforeStr=""; 
				

	for(var i=0;i<data["lsLogTypeListData"].length;i++){
		
		
		if(data["lsLogTypeListData"][i]["LOG_TYPE_ID"]=='4' || data["lsLogTypeListData"][i]["LOG_TYPE_ID"]=='5' || data["lsLogTypeListData"][i]["LOG_TYPE_ID"]=='6'){
			if(typesId==data["lsLogTypeListData"][i]["LOG_TYPE_ID"]){
				
				beforeStr+= '<option value="'+data["lsLogTypeListData"][i]["LOG_TYPE_ID"]+'" >'+data["lsLogTypeListData"][i]["LOG_TYPE_NAME"]+'</option>';
				
			}else{
				
				if(i==0 && typesId=="" && setTypeIdFlag)
					setType(data["lsLogTypeListData"][0]["LOG_TYPE_ID"]);
				
				
				typeListHtmlStr += '<option value="'+data["lsLogTypeListData"][i]["LOG_TYPE_ID"]+'" >'+data["lsLogTypeListData"][i]["LOG_TYPE_NAME"]+'</option>';

			}
		}
		
		
		
		
		
	}
	if(!setTypeIdFlag){
		beforeStr+='<option value="-1" >全部类型</option>';
	}
	
	typeListHtmlStr=beforeStr+typeListHtmlStr;
	
	$("#"+out_put_id).html(typeListHtmlStr);

	setSelectStyle();
	
	$('#'+out_put_id).change(function(){ 
		
		if($(this).children('option:selected').val()!="-1"){
			setType($(this).children('option:selected').val());
			
		}
	});
	
	
}



function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
}


//暴露方法
//exports.loadqueryTerminalLogsList=loadqueryTerminalLogsList;

exports.getQueryTerminalLogs=getQueryTerminalLogs;
exports.loadqueryTerminalLogsListCallBack=loadqueryTerminalLogsListCallBack;
exports.resetSearchParams=resetSearchParams;
exports.searchTerminalLogs=searchTerminalLogs;
exports.getTypeListCallBack=getTypeListCallBack;

});
//})();